package com.guoxin.part1.chapter1;

import java.util.concurrent.TimeUnit;

/**
 * @author guoxin
 * @date 2019/8/26
 */
public class TryConcurrency {
    public static void main(String[] args) {
        new Thread(TryConcurrency::browseNews).start();
        enjoyMusic();
    }

    /**
     * Browse the latest news.
     */
    private static void browseNews(){
        for(;;){
            System.out.println("Uh-huh, the good news.");
            sleep(1);
        }
    }

    private static void enjoyMusic(){
        for(;;){
            System.out.println("Uh-huh, the nice music.");
            sleep(1);
        }
    }

    private static void sleep(int seconds){
        try {
            TimeUnit.SECONDS.sleep(seconds);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
